package com.xxcxcxcx.jobsystem.common.command.argumets;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class JobParameterArgument implements ArgumentType<String> {
    public static final String LEVEL = "level";
    public static final String EXPERIENCE = "experience";
    public static final String COEFFICIENT = "coefficient";
    public static final List<String> JobParameters = Arrays.asList(LEVEL, EXPERIENCE, COEFFICIENT);

    protected JobParameterArgument() {

    }

    @Override
    public String parse(StringReader reader) throws CommandSyntaxException {
        String str = reader.readString();
        if(JobParameters.stream().anyMatch(i -> i.equals(str))) {
            return str;
        } else {
            throw new IllegalArgumentException("Not an available parameter.");
        }
    }

    @Override
    public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
        return SharedSuggestionProvider.suggest(JobParameters, builder);
    }

    @Override
    public Collection<String> getExamples() {
        return JobParameters;
    }

    public static String getJobParameter(CommandContext<CommandSourceStack> pContext, String pName) throws CommandSyntaxException {
        return pContext.getArgument(pName, String.class);
    }

    public static JobParameterArgument jobParameter() {
        return new JobParameterArgument();
    }
}
